<!DOCTYPE html>
<style>
    body {
        height: 2000px;
        width: 2000px;
    }
    ::-webkit-scrollbar {
      width: 0px;
      height: 0px;
    }
</style>

<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>

<script>
  function viewport() {
    return window.visualViewport;
  }

  async_test(function(t) {
    window.onload = t.step_func(function() {
      // Turn off smooth scrolling.
      internals.settings.setScrollAnimatorEnabled(false);

      window.scrollTo(100, 100);

      // Initial viewport dimensions.
      assert_equals(viewport().width, 800, "initial width");
      assert_equals(viewport().height, 600, "initial height");
      assert_equals(viewport().offsetLeft, 0, "initial offsetLeft");
      assert_equals(viewport().offsetTop, 0, "initial offsetTop");
      assert_equals(viewport().pageLeft, 100, "initial pageLeft");
      assert_equals(viewport().pageTop, 100, "initial pageTop");
      assert_equals(viewport().scale, 1, "initial scale");

      // Scale and scroll visual viewport.
      internals.setPageScaleFactor(2);
      internals.setVisualViewportOffset(10, 10);
      assert_equals(viewport().width, 400, "scaled width");
      assert_equals(viewport().height, 300, "scaled height");
      assert_equals(viewport().offsetLeft, 10, "scrolled left viewport");
      assert_equals(viewport().offsetTop, 10, "scrolled top viewport");
      assert_equals(viewport().pageLeft, 110, "initial pageLeft");
      assert_equals(viewport().pageTop, 110, "initial pageTop");
      assert_equals(viewport().scale, 2, "scale");

      // Set offsetTop/Left.
      internals.setVisualViewportOffset(0, 20);
      assert_equals(viewport().offsetTop, 20, "set offsetTop");
      assert_equals(viewport().offsetLeft, 0, "set offsetLeft");
      internals.setVisualViewportOffset(-20, -20);
      assert_equals(viewport().offsetTop, 0, "negative offsetTop");
      assert_equals(viewport().offsetTop, 0, "negative offsetLeft");

      t.done();
    });
  }, 'Verify viewport dimensions');
</script>

